import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import dataImportCreate from '../../addons/DataImport'
const daoName = "COMP_XWPH_TZ";
const ButtonGroup = Button.Group;
const columns = [
    { title: '序号', width: 250, sorter: true, dataIndex: 'XH', key: 'XH', dispaly: true, filter: true, export: true },
    { title: '客户组织机构代码', width: 250, sorter: true, dataIndex: 'ZZJGDM', key: 'ZZJGDM', dispaly: true, filter: true, export: true },
    { title: '合同编号', width: 250, sorter: true, dataIndex: 'HTBH', key: 'HTBH', dispaly: true, filter: true, export: true },
    { title: '客户名称', width: 250, sorter: true, dataIndex: 'KHMC', key: 'KHMC', dispaly: true, filter: true, export: true },
    { title: '经营单位', width: 250, sorter: true, dataIndex: 'JYDW', key: 'JYDW', dispaly: true, filter: true, export: true },
    { title: '借据编号', width: 250, sorter: true, dataIndex: 'JJBH', key: 'JJBH', dispaly: true, filter: true, export: true },
    { title: '所属授信协议号', width: 250, sorter: true, dataIndex: 'SSSXXYH', key: 'SSSXXYH', dispaly: true, filter: true, export: true },
    { title: '授信使用名称', width: 250, sorter: true, dataIndex: 'SXSYMC', key: 'SXSYMC', dispaly: true, filter: true, export: true },
    { title: '是否使用授信', width: 250, sorter: true, dataIndex: 'SFSYSX', key: 'SFSYSX', dispaly: true, filter: true, export: true },
    { title: '授信', width: 250, sorter: true, dataIndex: 'SX', key: 'SX', dispaly: true, filter: true, export: true },
    { title: '认定授信', width: 250, sorter: true, dataIndex: 'RDSX', key: 'RDSX', dispaly: true, filter: true, export: true },
    { title: '授信1000', width: 250, sorter: true, dataIndex: 'SX1000', key: 'SX1000', dispaly: true, filter: true, export: true },
    { title: '认定户数', width: 250, sorter: true, dataIndex: 'RDHS', key: 'RDHS', dispaly: true, filter: true, export: true },
    { title: '余额', width: 250, sorter: true, dataIndex: 'YE', key: 'YE', dispaly: true, filter: true, export: true },
    { title: '余额万元', width: 250, sorter: true, dataIndex: 'YEWY', key: 'YEWY', dispaly: true, filter: true, export: true },
    { title: '调查人', width: 250, sorter: true, dataIndex: 'DCR', key: 'DCR', dispaly: true, filter: true, export: true },
    { title: '审查人', width: 250, sorter: true, dataIndex: 'SCR', key: 'SCR', dispaly: true, filter: true, export: true },
    { title: '币种', width: 250, sorter: true, dataIndex: 'BZ', key: 'BZ', dispaly: true, filter: true, export: true },
    { title: '新国标行业分类', width: 250, sorter: true, dataIndex: 'XGBHYFL', key: 'XGBHYFL', dispaly: true, filter: true, export: true },
    { title: '企业规模（四部委）', width: 250, sorter: true, dataIndex: 'QYGM', key: 'QYGM', dispaly: true, filter: true, export: true },
    { title: '客户类型', width: 250, sorter: true, dataIndex: 'KHLX', key: 'KHLX', dispaly: true, filter: true, export: true },
    { title: '业务品种', width: 250, sorter: true, dataIndex: 'YWPZ', key: 'YWPZ', dispaly: true, filter: true, export: true },
    { title: '业务类型', width: 250, sorter: true, dataIndex: 'YWLX', key: 'YWLX', dispaly: true, filter: true, export: true },
    { title: '合同金额', width: 250, sorter: true, dataIndex: 'HTJE', key: 'HTJE', dispaly: true, filter: true, export: true },
    { title: '主要担保方式', width: 250, sorter: true, dataIndex: 'ZYDBFS', key: 'ZYDBFS', dispaly: true, filter: true, export: true },
    { title: '担保人名称', width: 250, sorter: true, dataIndex: 'DBRMC', key: 'DBRMC', dispaly: true, filter: true, export: true },
    { title: '信贷产品种类', width: 250, sorter: true, dataIndex: 'XDCPZL', key: 'XDCPZL', dispaly: true, filter: true, export: true },
    { title: '最初放款日', width: 250, sorter: true, dataIndex: 'ZCFKR', key: 'ZCFKR', dispaly: true, filter: true, export: true },
    { title: '起始日', width: 250, sorter: true, dataIndex: 'QXR', key: 'QXR', dispaly: true, filter: true, export: true },
    { title: '到期日', width: 250, sorter: true, dataIndex: 'DQR', key: 'DQR', dispaly: true, filter: true, export: true },
    { title: '终结日期', width: 250, sorter: true, dataIndex: 'ZJR', key: 'ZJR', dispaly: true, filter: true, export: true },
    { title: '贷款金额', width: 250, sorter: true, dataIndex: 'DKJE', key: 'DKJE', dispaly: true, filter: true, export: true },
    { title: '借据利率类型', width: 250, sorter: true, dataIndex: 'JJLLLX', key: 'JJLLLX', dispaly: true, filter: true, export: true },
    { title: '借据利率浮动', width: 250, sorter: true, dataIndex: 'JJLXFD', key: 'JJLXFD', dispaly: true, filter: true, export: true },
    { title: '执行年利率', width: 250, sorter: true, dataIndex: 'ZXNLL', key: 'ZXNLL', dispaly: true, filter: true, export: true },
    { title: '发生类型', width: 250, sorter: true, dataIndex: 'FSLX', key: 'FSLX', dispaly: true, filter: true, export: true },
    { title: '入帐机构', width: 250, sorter: true, dataIndex: 'RZJG', key: 'RZJG', dispaly: true, filter: true, export: true },
    { title: '金融系统首贷（征信）', width: 250, sorter: true, dataIndex: 'JRXTSD', key: 'JRXTSD', dispaly: true, filter: true, export: true },
    { title: '国内定价利率', width: 250, sorter: true, dataIndex: 'GNDJLL', key: 'GNDJLL', dispaly: true, filter: true, export: true },
    { title: '利率属性', width: 250, sorter: true, dataIndex: 'LLSX', key: 'LLSX', dispaly: true, filter: true, export: true },
    { title: '所在地区', width: 250, sorter: true, dataIndex: 'SZDQ', key: 'SZDQ', dispaly: true, filter: true, export: true },
    { title: '注册地址', width: 250, sorter: true, dataIndex: 'ZCDZ', key: 'ZCDZ', dispaly: true, filter: true, export: true },
    { title: '员工人数', width: 250, sorter: true, dataIndex: 'YGRS', key: 'YGRS', dispaly: true, filter: true, export: true },
    { title: '贷款投向行业', width: 250, sorter: true, dataIndex: 'DKTXHY', key: 'DKTXHY', dispaly: true, filter: true, export: true },
    { title: '贷款卡编号', width: 250, sorter: true, dataIndex: 'DKKBH', key: 'DKKBH', dispaly: true, filter: true, export: true },
    { title: '经济组织类型', width: 250, sorter: true, dataIndex: 'JJZZLX', key: 'JJZZLX', dispaly: true, filter: true, export: true },
    { title: '企业出资人经济成分', width: 250, sorter: true, dataIndex: 'QYCZRCF', key: 'QYCZRCF', dispaly: true, filter: true, export: true },
    { title: '是否国家或省级国资委所属企业', width: 250, sorter: true, dataIndex: 'SFGJ', key: 'SFGJ', dispaly: true, filter: true, export: true },
    { title: '营业执照号码', width: 250, sorter: true, dataIndex: 'YYZZ', key: 'YYZZ', dispaly: true, filter: true, export: true },
    { title: '是否高新科技企业', width: 250, sorter: true, dataIndex: 'SFGXY', key: 'SFGXY', dispaly: true, filter: true, export: true },
    { title: '企业规模（2011自动）', width: 250, sorter: true, dataIndex: 'QYGM2', key: 'QYGM2', dispaly: true, filter: true, export: true },
    { title: '流程名称', width: 250, sorter: true, dataIndex: 'LCMC', key: 'LCMC', dispaly: true, filter: true, export: true },
    { title: '是否银团', width: 250, sorter: true, dataIndex: 'SFYT', key: 'SFYT', dispaly: true, filter: true, export: true },
    { title: '贷款账号', width: 250, sorter: true, dataIndex: 'DKZH', key: 'DKZH', dispaly: true, filter: true, export: true },
    { title: '还款方式', width: 250, sorter: true, dataIndex: 'HKFS', key: 'HKFS', dispaly: true, filter: true, export: true },
    { title: '利息支付方式', width: 250, sorter: true, dataIndex: 'LXZFFS', key: 'LXZFFS', dispaly: true, filter: true, export: true },];
const controls = [
    { name: "XH", label: "序号", type: "text", grid: 12 / 24 },
    { name: "ZZJGDM", label: "客户组织机构代码", type: "text", grid: 12 / 24 },
    { name: "HTBH", label: "合同编号", type: "text", grid: 12 / 24 },
    { name: "KHMC", label: "客户名称", type: "text", grid: 12 / 24 },
    { name: "JYDW", label: "经营单位", type: "text", grid: 12 / 24 },
    { name: "JJBH", label: "借据编号", type: "text", grid: 12 / 24 },
    { name: "SSSXXYH", label: "所属授信协议号", type: "text", grid: 12 / 24 },
    { name: "SXSYMC", label: "授信使用名称", type: "text", grid: 12 / 24 },
    { name: "SFSYSX", label: "是否使用授信", type: "text", grid: 12 / 24 },
    { name: "SX", label: "授信", type: "text", grid: 12 / 24 },
    { name: "RDSX", label: "认定授信", type: "text", grid: 12 / 24 },
    { name: "SX1000", label: "授信1000", type: "text", grid: 12 / 24 },
    { name: "RDHS", label: "认定户数", type: "text", grid: 12 / 24 },
    { name: "YE", label: "余额", type: "text", grid: 12 / 24 },
    { name: "YEWY", label: "余额万元", type: "text", grid: 12 / 24 },
    { name: "DCR", label: "调查人", type: "text", grid: 12 / 24 },
    { name: "SCR", label: "审查人", type: "text", grid: 12 / 24 },
    { name: "BZ", label: "币种", type: "text", grid: 12 / 24 },
    { name: "XGBHYFL", label: "新国标行业分类", type: "text", grid: 12 / 24 },
    { name: "QYGM", label: "企业规模（四部委）", type: "text", grid: 12 / 24 },
    { name: "KHLX", label: "客户类型", type: "text", grid: 12 / 24 },
    { name: "YWPZ", label: "业务品种", type: "text", grid: 12 / 24 },
    { name: "YWLX", label: "业务类型", type: "text", grid: 12 / 24 },
    { name: "HTJE", label: "合同金额", type: "text", grid: 12 / 24 },
    { name: "ZYDBFS", label: "主要担保方式", type: "text", grid: 12 / 24 },
    { name: "DBRMC", label: "担保人名称", type: "text", grid: 12 / 24 },
    { name: "XDCPZL", label: "信贷产品种类", type: "text", grid: 12 / 24 },
    { name: "ZCFKR", label: "最初放款日", type: "text", grid: 12 / 24 },
    { name: "QXR", label: "起始日", type: "text", grid: 12 / 24 },
    { name: "DQR", label: "到期日", type: "text", grid: 12 / 24 },
    { name: "ZJR", label: "终结日期", type: "text", grid: 12 / 24 },
    { name: "DKJE", label: "贷款金额", type: "text", grid: 12 / 24 },
    { name: "JJLLLX", label: "借据利率类型", type: "text", grid: 12 / 24 },
    { name: "JJLXFD", label: "借据利率浮动", type: "text", grid: 12 / 24 },
    { name: "ZXNLL", label: "执行年利率", type: "text", grid: 12 / 24 },
    { name: "FSLX", label: "发生类型", type: "text", grid: 12 / 24 },
    { name: "RZJG", label: "入帐机构", type: "text", grid: 12 / 24 },
    { name: "JRXTSD", label: "金融系统首贷（征信）", type: "text", grid: 12 / 24 },
    { name: "GNDJLL", label: "国内定价利率", type: "text", grid: 12 / 24 },
    { name: "LLSX", label: "利率属性", type: "text", grid: 12 / 24 },
    { name: "SZDQ", label: "所在地区", type: "text", grid: 12 / 24 },
    { name: "ZCDZ", label: "注册地址", type: "text", grid: 12 / 24 },
    { name: "YGRS", label: "员工人数", type: "text", grid: 12 / 24 },
    { name: "DKTXHY", label: "贷款投向行业", type: "text", grid: 12 / 24 },
    { name: "DKKBH", label: "贷款卡编号", type: "text", grid: 12 / 24 },
    { name: "JJZZLX", label: "经济组织类型", type: "text", grid: 12 / 24 },
    { name: "QYCZRCF", label: "企业出资人经济成分", type: "text", grid: 12 / 24 },
    { name: "SFGJ", label: "是否国家或省级国资委所属企业", type: "text", grid: 12 / 24 },
    { name: "YYZZ", label: "营业执照号码", type: "text", grid: 12 / 24 },
    { name: "SFGXY", label: "是否高新科技企业", type: "text", grid: 12 / 24 },
    { name: "QYGM2", label: "企业规模（2011自动）", type: "text", grid: 12 / 24 },
    { name: "LCMC", label: "流程名称", type: "text", grid: 12 / 24 },
    { name: "SFYT", label: "是否银团", type: "text", grid: 12 / 24 },
    { name: "DKZH", label: "贷款账号", type: "text", grid: 12 / 24 },
    { name: "HKFS", label: "还款方式", type: "text", grid: 12 / 24 },
    { name: "LXZFFS", label: "利息支付方式", type: "text", grid: 12 / 24 },
];
const controlsDtip = [
    { name: "XH", label: "序号", type: "text", grid: 12 / 24 },
    { name: "ZZJGDM", label: "客户组织机构代码", type: "text", grid: 12 / 24 },
    { name: "HTBH", label: "合同编号", type: "text", grid: 12 / 24 },
    { name: "KHMC", label: "客户名称", type: "text", grid: 12 / 24 },
    { name: "JYDW", label: "经营单位", type: "text", grid: 12 / 24 },
    { name: "JJBH", label: "借据编号", type: "text", grid: 12 / 24 },
    { name: "SSSXXYH", label: "所属授信协议号", type: "text", grid: 12 / 24 },
    { name: "SXSYMC", label: "授信使用名称", type: "text", grid: 12 / 24 },
    { name: "SFSYSX", label: "是否使用授信", type: "text", grid: 12 / 24 },
    { name: "SX", label: "授信", type: "text", grid: 12 / 24 },
    { name: "RDSX", label: "认定授信", type: "text", grid: 12 / 24 },
    { name: "SX1000", label: "授信1000", type: "text", grid: 12 / 24 },
    { name: "RDHS", label: "认定户数", type: "text", grid: 12 / 24 },
    { name: "YE", label: "余额", type: "text", grid: 12 / 24 },
    { name: "YEWY", label: "余额万元", type: "text", grid: 12 / 24 },
    { name: "DCR", label: "调查人", type: "text", grid: 12 / 24 },
    { name: "SCR", label: "审查人", type: "text", grid: 12 / 24 },
    { name: "BZ", label: "币种", type: "text", grid: 12 / 24 },
    { name: "XGBHYFL", label: "新国标行业分类", type: "text", grid: 12 / 24 },
    { name: "QYGM", label: "企业规模（四部委）", type: "text", grid: 12 / 24 },
    { name: "KHLX", label: "客户类型", type: "text", grid: 12 / 24 },
    { name: "YWPZ", label: "业务品种", type: "text", grid: 12 / 24 },
    { name: "YWLX", label: "业务类型", type: "text", grid: 12 / 24 },
    { name: "HTJE", label: "合同金额", type: "text", grid: 12 / 24 },
    { name: "ZYDBFS", label: "主要担保方式", type: "text", grid: 12 / 24 },
    { name: "DBRMC", label: "担保人名称", type: "text", grid: 12 / 24 },
    { name: "XDCPZL", label: "信贷产品种类", type: "text", grid: 12 / 24 },
    { name: "ZCFKR", label: "最初放款日", type: "text", grid: 12 / 24 },
    { name: "QXR", label: "起始日", type: "text", grid: 12 / 24 },
    { name: "DQR", label: "到期日", type: "text", grid: 12 / 24 },
    { name: "ZJR", label: "终结日期", type: "text", grid: 12 / 24 },
    { name: "DKJE", label: "贷款金额", type: "text", grid: 12 / 24 },
    { name: "JJLLLX", label: "借据利率类型", type: "text", grid: 12 / 24 },
    { name: "JJLXFD", label: "借据利率浮动", type: "text", grid: 12 / 24 },
    { name: "ZXNLL", label: "执行年利率", type: "text", grid: 12 / 24 },
    { name: "FSLX", label: "发生类型", type: "text", grid: 12 / 24 },
    { name: "RZJG", label: "入帐机构", type: "text", grid: 12 / 24 },
    { name: "JRXTSD", label: "金融系统首贷（征信）", type: "text", grid: 12 / 24 },
    { name: "GNDJLL", label: "国内定价利率", type: "text", grid: 12 / 24 },
    { name: "LLSX", label: "利率属性", type: "text", grid: 12 / 24 },
    { name: "SZDQ", label: "所在地区", type: "text", grid: 12 / 24 },
    { name: "ZCDZ", label: "注册地址", type: "text", grid: 12 / 24 },
    { name: "YGRS", label: "员工人数", type: "text", grid: 12 / 24 },
    { name: "DKTXHY", label: "贷款投向行业", type: "text", grid: 12 / 24 },
    { name: "DKKBH", label: "贷款卡编号", type: "text", grid: 12 / 24 },
    { name: "JJZZLX", label: "经济组织类型", type: "text", grid: 12 / 24 },
    { name: "QYCZRCF", label: "企业出资人经济成分", type: "text", grid: 12 / 24 },
    { name: "SFGJ", label: "是否国家或省级国资委所属企业", type: "text", grid: 12 / 24 },
    { name: "YYZZ", label: "营业执照号码", type: "text", grid: 12 / 24 },
    { name: "SFGXY", label: "是否高新科技企业", type: "text", grid: 12 / 24 },
    { name: "QYGM2", label: "企业规模（2011自动）", type: "text", grid: 12 / 24 },
    { name: "LCMC", label: "流程名称", type: "text", grid: 12 / 24 },
    { name: "SFYT", label: "是否银团", type: "text", grid: 12 / 24 },
    { name: "DKZH", label: "贷款账号", type: "text", grid: 12 / 24 },
    { name: "HKFS", label: "还款方式", type: "text", grid: 12 / 24 },
    { name: "LXZFFS", label: "利息支付方式", type: "text", grid: 12 / 24 },];
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
const DataImport = dataImportCreate(daoName);
class PhxwTzdrForm extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID", permID: this.props.permID }
        });
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 10 }
        });
        this.loadOptionData();
    }
    componentWillReceiveProps(nextProps) {
        const { showImport } = this.props
        if (!nextProps.showImport && showImport) {
            this.props.dispatch({
                type: `${daoName}/fetch`,
                payload: { daoName, page: 1, pageSize: 10 }
            });
        }
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showImportHandler() {
        this.props.dispatch({
            type: `${daoName}_DataImport/setDisplay`,
            payload: { display: true },
        });
    }
    DownTmportHandler() {
        let columnHeaders = []
        columns.map((c, j) => {
            if (!c.export) {
                return
            }
            let header = {
                Name: c.key,
                Caption: c.title,
                Width: c.width
            }
            columnHeaders.push(header)
        })
        let form = document.createElement('form');//定义一个form表单
        let whereItems = [];
        whereItems.push({
            FieldName: "1",
            Operator: "<>",
            FieldValues: "1"
        })
        const whereCauses = []
        whereCauses.push({
            WhereItems: whereItems,
            RelationSign: "AND"
        })
        const orderItems = []
        form.style = "display:none";
        form.target = "_blank";
        form.method = "post";
        form.action = "/api/ExportXlsx/" + daoName;
        let input1 = document.createElement("input");
        input1.type = "hidden";
        input1.name = "WhereCauses";
        input1.value = JSON.stringify(whereCauses);
        let input2 = document.createElement("input");
        input2.type = "hidden";
        input2.name = "OrderItems";
        input2.value = JSON.stringify(orderItems)
        let input3 = document.createElement("input");
        input3.type = "hidden";
        input3.name = "ColumnHeaders";
        input3.value = JSON.stringify(columnHeaders);
        let input4 = document.createElement("input");
        input4.type = "hidden";
        input4.name = "PermID";
        input4.value = "" + this.props.permID;
        let input5 = document.createElement("input");
        input5.type = "hidden";
        input5.name = "UserID";
        input5.value = "" + this.props.userID;
        document.body.appendChild(form);//将表单放置在web中
        form.appendChild(input1);
        form.appendChild(input2);
        form.appendChild(input3);
        form.appendChild(input4);
        form.appendChild(input5);
        form.submit();
        document.body.removeChild(form)
    }
    render() {
        let { showEdit, record, showImport, permID, popedomTypes } = this.props
        let pTypes = popedomTypes[permID]
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        <ButtonGroup style={{ zIndex: 0 }}>
                            <Button onClick={this.showImportHandler.bind(this)}>导入</Button>
                            <Button onClick={this.DownTmportHandler.bind(this)}>下载模板</Button>
                        </ButtonGroup>
                    </div>
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID} />
                    <DataImport title="导入" importName="COMP_XWPH_TZ" daoName="COMP_XWPH_TZ" importMode="TruncteAfterInsert" controls={controls} />
                </div>
            </div>
        )
    }
}

function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    const { userID, orgID, pOrgID, popedomTypes } = state.menus;
    const { display } = state[`${daoName}_DataImport`];
    return {
        userID,
        orgID,
        pOrgID,
        popedomTypes,
        showEdit,
        selectedRowKeys,
        keyName,
        record,
        showImport: display
    }
}
PhxwTzdrForm = connect(mapStateToProps)(PhxwTzdrForm)
export default PhxwTzdrForm;

let render = (props) => React.createElement(PhxwTzdrForm, props);
let f = new Factory()
f.set("PhxwTzdrForm", render)
